/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bcit.nxt.mission;

import gin.and.tonic.*;
import lejos.nxt.Button;
import lejos.nxt.ButtonListener;

/**
 *
 * @author Steed
 */
public class SensorPolling implements ButtonListener
{

    private DragonRobot robot = new DragonRobot();
    public boolean isRunning = true;

    public SensorPolling()
    {

        Button.ESCAPE.addButtonListener(this);
        UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
        TouchSensor ts = new TouchSensor(SensorPort.S2);
        LightSensor lsLeft = new LightSensor(SensorPort.S3);
        LightSensor lsRight = new LightSensor(SensorPort.S4);
        

        robot.addPart(us);
        robot.addPart(ts);
        robot.addPart(lsLeft);
        robot.addPart(lsRight);

        lsLeft.activate(true);
        lsRight.activate(true);

        robot.getGear().forward();
        while (isRunning)
        {
            if (us.getDistance() < 10)
            {
                robot.getGear().stop();
                robot.left(90);
                robot.getGear().forward();
            }

            if (ts.isPressed())
            {
               break;

            }
            if (lsLeft.getValue() < 340 || lsLeft.getValue() < 340)
            {
                robot.getGear().stop();
                robot.backward(50);
                robot.left(90);
                robot.getGear().forward();
            }
        }
        robot.exit();
    }

    public void buttonPressed(Button b)
    {
        isRunning = false;
    }

    public void buttonReleased(Button b)
    {
    }

    public static void main(String[] argv)
    {
        new SensorPolling();
    }
}
